
/*

DEPENDENCIES:
-------------
Gimme.Effects
ext.get_style
ext.set_style
-------------


IN THIS FILE:
-------------
ext.animate
-------------

*/

Gimme.ext.animate = function(props, duration, guid, callback, easing)
{
	function doOp(op, a, b)
	{
		switch (op)
		{
			case '+':
				return a + b;
			case '-':
				return a - b;
			case '*':
				return a * b;
			case '/':
				return a / b;
			default:
				return b;
		}
	}

	function getFrom(elem, key)
	{
		var v = Gimme(elem).get_style(key) + '';
		var f = parseFloat(v);
		from.units[key] = v.replace(f, '');
		return f;
	}

	function getTo(elem, key)
	{
		var f = getFrom(elem, key);
		var t = props[key] + '';
		var m = t.match(/^[+\-*\/]/);
		var op = m && m[0] || 'noOp';
		t = Number(t.replace(op, ''));		
		return doOp(op, f, t);
	}

	var from = {units: {}, ops: {}}, to = {};
	for (var key in props)
	{
		from[key] = getFrom;
		to[key] = getTo;
	}
	
	var sb = Gimme.Effects.Storyboard.create(this, from, to, function(elem, p)
	{
		var gim = Gimme(elem);
		for (var k in p)
		{
			if (k === 'units') continue;
			var d = {};
			d[k] = p[k] + from.units[k];
			gim.set_style(d);
		}
	},
	duration,
	guid,
	callback,			
	easing);

	sb.begin();
	return this;
};
